﻿<Window x:Class="PresentItNow.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:PresentItNow"
        Title="Present It Now!" Height="330" Width="400"
        >
    <Window.Resources>
        <local:ModeToVisibilityConverter x:Key="modeConverter"/>
        <local:VisibilityConverter x:Key="visibilityConverter"/>
        <local:OperationModeConverter x:Key="operationModeConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Menu>
            <MenuItem Header="Help" >
                <MenuItem Header="About" Click="menuAbout_Clicked"/>
            </MenuItem>
        </Menu>
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid  Background="Gray" >
            <TextBlock Text="{Binding CurrentMode, Converter={StaticResource operationModeConverter}}" FontSize="30" Foreground="White"
                       Margin="10,0,10,0"/>
            </Grid>
            <!-- Start -->
            <Grid Grid.Row="1">
                <Grid Visibility="{Binding CurrentMode, Converter={StaticResource modeConverter}, ConverterParameter=Start, Mode=OneWay}" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <DockPanel VerticalAlignment="Center" Margin="10">
                        <TextBlock Text="Enter a name: " DockPanel.Dock="Left" VerticalAlignment="Center" FontSize="16"/>
                        <TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"  FontSize="16"/>

                    </DockPanel>

                    <Button Content="I want to present" FontSize="20" Grid.Row="1" Margin="10" Command="local:Commands.StartHost" Height="50"/>
                    <Button Content="I want to view" FontSize="20" Grid.Row="2" Margin="10" Command="local:Commands.StartClient"  Height="50"/>
                </Grid>

                <Grid Visibility="{Binding CurrentMode, Converter={StaticResource modeConverter}, ConverterParameter=Host, Mode=OneWay}" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Button Content="Stop presenting" Command="local:Commands.StopHost"  Height="50" Margin="10"
                        FontSize="20"/>
                    <StackPanel VerticalAlignment="Center" Grid.Row="1" MinHeight="100" Margin="10">
                        <TextBlock Text="Your IP Address(es):" FontSize="20"/>
                        <ItemsControl ItemsSource="{Binding HostIPs}" >
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBox Text="{Binding Mode=OneWay}" FontSize="16" Foreground="Blue" BorderThickness="0" IsReadOnly="True"/>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </Grid>


                <Grid Visibility="{Binding CurrentMode, Converter={StaticResource modeConverter}, ConverterParameter=Client_Disconnected, Mode=OneWay}" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <DockPanel VerticalAlignment="Center" Margin="10">
                        <TextBlock Text="IP address of the presenter: " DockPanel.Dock="Left" VerticalAlignment="Center" FontSize="16"/>
                        <TextBox Text="{Binding HostIP, UpdateSourceTrigger=PropertyChanged}"  FontSize="16"/>
                    </DockPanel>
                    <Button Content="Connect" Command="local:Commands.Connect"  Height="50" Margin="10"
                        Grid.Row="1"
                        FontSize="20"/>
                </Grid>

                <Grid Visibility="{Binding CurrentMode, Converter={StaticResource modeConverter}, ConverterParameter=Client_Connected, Mode=OneWay}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <StackPanel Margin="10">
                        <TextBlock Text="Adjust quality:" Margin="0,10,0,0"/>
                        <Slider Minimum="1" Maximum="100" TickFrequency="1" 
                            Value="{Binding Quality}"/>
                    </StackPanel>
                    <Button Content="Disconnect" Command="local:Commands.Disconnect"  Height="50" Margin="10"
                        Grid.Row="1"
                        FontSize="20"/>
                </Grid>
            </Grid>
        </Grid>
        <!-- Wait "overlay" -->
        <Grid Visibility="{Binding AsyncExecutor.IsBusy, Converter={StaticResource visibilityConverter}}" Background="Transparent" Cursor="Wait"
              Grid.Row="1">            
            <ProgressBar IsIndeterminate="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Opacity="0.6"/>
            <TextBlock Text="{Binding WaitMessage}" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </Grid>
    </Grid>


</Window>
